#include <iostream>
#include <unordered_set>
#include <vector>

class Solution {
public:
    int maxProfit_(std::vector<int> &prices) {
        if (prices.empty())
            return 0;
        int profit = 0;
        for (int i = 1; i < prices.size(); ++i) {
            if (prices[i] > prices[i - 1]) {
                profit += prices[i] - prices[i - 1];
            }
        }
        return profit;
    }

    bool containsDuplicate(std::vector<int> &nums) {
        std::unordered_set<int> s;
        for (auto num : nums) {
            if (s.count(num)) {
                return true;
            } else {
                s.insert(num);
            }
        }
        return false;
    }

    int maxProfit(std::vector<int> &prices) {
        if (prices.empty())
            return 0;
        int pre = prices[0]; // 可以直接用prices[i-1]...
        int buy_prices = prices[0];
        int profit = 0;
        for (auto p : prices) {
            if (p <= pre) {
                profit += pre - buy_prices;
                buy_prices = p;
            }
            pre = p;
        }
        return profit + (pre - buy_prices);
    }

    int removeDuplicates(std::vector<int> &nums) {
        if (nums.empty())
            return 0;
        int pre = nums[0], cur_i = 1, count = 1;
        for (int i = 1; i < nums.size(); ++i) {
            if (nums[i] != pre) {
                pre = nums[i];
                ++count;
                nums[cur_i] = nums[i];
                ++cur_i;
            }
        }
        return count;
    }
};

void removexx_test() {
    std::vector<int> nums{1, 1, 2, 2, 3};
    Solution s;
    std::cout << s.removeDuplicates(nums) << '\n';
    for (auto v : nums) {
        std::cout << v << ", ";
    }
    std::cout << '\n';
}

int main() {}